<template>
  <cl-select v-bind="$props" v-on="$listeners" :value="value">
    <el-option v-if="showAll" label="全部" value="" />
    <el-option v-for="item in list" :key="item.dept_id"
      :label="`${item.dept_name}(${$constFilter(item.ctype, 'CTYPE_LIST')})`" :value="item.dept_id">
      {{ item.dept_name }}

      <span style="color: #8492a6; font-size: 12px">
        (<span :class="{ 'red': item.ctype == 1 }">{{ item.ctype | constFilter("CTYPE_LIST") }}</span> -
        {{ item.bus_state_name }})
      </span>
    </el-option>
  </cl-select>
</template>
<script>
import Select from "@/cool/modules/base/components/select/index.vue";
// 门店选择
export default {
  name: "cl-shop-select",
  props: {
    ...Select.props,
    // 列表
    options: {
      type: Array,
      default: () => []
    },
    // 只展示营业
    onlyOpen: {
      type: Boolean,
      default: false
    },
    // 展示全部选项
    showAll: {
      type: Boolean,
      default: false
    },
    // 事业部ID
    biz_id: {
      type: [Number, String]
    },
    // 区域ID
    region_id: {
      type: [Number, String]
    },
    needKeyword: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {};
  },
  computed: {
    shopList() {
      console.info("this.shop_childs", this.biz_id)
      return this.getBizRefData(this.biz_id, "shop_childs");
    },

    list() {
      let shopList = !!this.biz_id ? this.shopList : this.options;
      let list = shopList
      if (this.region_id) {
        list = shopList.filter((v) => v.region_id == this.region_id)
      }
      if (!this.onlyOpen) return list;
      return list.filter((v) => v.bus_state == 1);
    }
  }
};
</script>
<style>
.red {
  color: red
}
</style>
